//
//  YFNearVCHeaderView.m
//  QuanJieShopProject
//
//  Created by apple on 2018/4/14.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFNearVCHeaderView.h"

#import "YFButtonCategoryView.h"
#import "YFHomeOneReusableView.h"
#import "YFShopAdView.h"

@interface YFNearVCHeaderView()
@property (nonatomic, strong) YFShopAdView *adView;
//@property (nonatomic, strong) YFButtonCategoryView *categoryView;
@property (nonatomic, strong) YFNearCategoryView *categoryView;

@property (nonatomic, strong) YFHomeOneReusableView *headOneView;
@property (nonatomic, strong) YFHomeOneReusableView *headTwoView;

@end
@implementation YFNearVCHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithRGBRed:245 green:245 blue:245];
        [self makeView];
    }
    return self;
}


- (void)makeView {
    
    // 顶部图片
    CGFloat topImgViewH = UISCREEN_WIDTH * 400.f/750.f;
    UIImageView *topImgView = [[UIImageView alloc] init];
    topImgView.frame = CGRectMake(0, 0, UISCREEN_WIDTH, topImgViewH);
    topImgView.image = [UIImage imageNamed:@"banner_near"];
    [self addSubview:topImgView];
    
    // 因为10个按钮距离顶部图片太近了,所以加个view, 不改背景颜色
    UIView *paddingLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topImgView.frame), UISCREEN_WIDTH, 10)];
    paddingLine.backgroundColor = [UIColor whiteColor];
    [self addSubview:paddingLine];
    
    // 十个按钮
    YFNearCategoryView *categoryView = [[YFNearCategoryView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(paddingLine.frame), UISCREEN_WIDTH, 0)];
    categoryView.mj_h = categoryView.height;
    [self addSubview:categoryView];
    kWeakSelf;
    categoryView.backgroundColor = [UIColor whiteColor];
    categoryView.buttonClickBlock = ^(NSInteger ZeroTag) {
        if (weakSelf.headerBtnClickBlock) {
            weakSelf.headerBtnClickBlock(ZeroTag);
        }
    };
    self.categoryView = categoryView;
    
    // 美食美客  80
    YFHomeOneReusableView *headOneView = [[YFHomeOneReusableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(categoryView.frame) + 10, UISCREEN_WIDTH, UISCREEN_HEIGHT * 80.f/1334.f)];
    headOneView.backgroundColor = [UIColor whiteColor];
    headOneView.title = @"美食美客";
    [self addSubview:headOneView];
    self.headOneView = headOneView;

    
    // 商铺广告  高度为0, 初始化内部再计算一遍
    CGFloat adViewH = 270.f/1334.f * UISCREEN_HEIGHT;
    YFShopAdView *adView = [[YFShopAdView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headOneView.frame), UISCREEN_WIDTH, adViewH)];
    adView.adImgViewClickBlock = ^(NearShopModel *model) {
        if (self.adImgViewClickBlock) {
            self.adImgViewClickBlock(model);
        }
    };
    adView.backgroundColor = [UIColor whiteColor];
    [self addSubview:adView];
    self.adView = adView;
    
    // 附近美食  80
    YFHomeOneReusableView *headTwoView = [[YFHomeOneReusableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(adView.frame) + 10, UISCREEN_WIDTH, UISCREEN_HEIGHT * 80.f/1334.f)];
    headTwoView.backgroundColor = [UIColor whiteColor];
    headTwoView.title = @"附近美食";
    [self addSubview:headTwoView];
    self.headTwoView = headTwoView;
    
    // 底部横线
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headTwoView.frame), UISCREEN_WIDTH, 0.5)];
    line.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
    [self addSubview:line];
    
    // 一共 820
    self.height = CGRectGetMaxY(line.frame);
    self.frame = CGRectMake(0, 0, UISCREEN_WIDTH, self.height);
}

- (void)setAdArray:(NSArray *)adArray {
    
    // 商铺广告赋值
    self.adView.adArray = adArray;
    
    _adArray = adArray;
}
@end
